package chai.ningning.myself;

import java.io.*;


public class CopyFile {

    public static void main(String[] args) throws IOException {

        FilenameFilter fods = new FilenameFilter(){

            @Override
            public boolean accept(File file, String name) {
                    if (name.endsWith(".java")){
                        return true;
                    }
                return false;
            }
        };

        File file = new File("E:/Code");
        File fileCopy = new File("E:/test");

        if (file.exists()){
            File[] fod = file.listFiles(fods);

            for (int i = 0; i <fod.length ; i++) {

                String a = fod[i].getName();
                //System.out.println(a);

                InputStream in = new FileInputStream(file+"/"+a);

                byte[] bytes = new byte[100];
                int b;
                File f =new File(fileCopy+"/"+a);
                if (false==f.exists()){
                    f.createNewFile();
                    OutputStream out = new FileOutputStream(f);
                    while ((b=in.read(bytes))!= -1){
                        out.write(bytes,0,b);
                    }
                    out.close();
                }
                in.close();
            }
        }else {
            System.out.println("不存在");
        }
    }
}
